<div class="users form">
<?php $session->flash(); ?>
<?php echo $form->create('User', array('id' => 'UserSignup', 'name' => 'UserSignup'));?>
	<fieldset>
 		<legend><?php __('Sign Up');?></legend>
                <div id="message_error"></div>
	<?php
		echo $this->Form->input('name', array('label' => 'Full name:<em class="required_field"> (required)</em><em id="UserNameUpdate"></em>'));
		echo $this->Form->input('username', array('label' => 'Username:<em class="required_field"> (required)</em><em id="UserUsernameUpdate"></em>'));

                echo $this->Html->tag('div', $this->Html->tag('label', __('Sex:', true), array('for' => 'userSex')).$this->Form->select('sex', array('female' => __('Female', true), 'male' => __('Male', true)), null, array('empty' => false, 'id' => 'userSex')), array());
                ?>
                <div>
                    <?php
                        echo $this->Html->tag('label', __('Date of Birth:', true), array('for' => 'day month year'));
                        echo $this->Form->day('day', null, array('id' => 'day', 'empty' => false, 'name' => 'data[User][day]'));
                        echo $this->Form->month('month', null, array('id' => 'month', 'empty' => false, 'name' => 'data[User][month]'));
                        echo $this->Form->year('year', 1920, 2010, null, array('id' => 'year', 'empty' => false, 'name' => 'data[User][year]'));
                    ?>
                </div>
                <?php
		echo $this->Form->input('email', array('label' => 'Email:<em class="required_field"> (required)</em><em id="UserEmailUpdate"></em>'));
		echo $this->Form->input('text_password', array('type' => 'password', 'label' => 'Password:<em class="required_field"> (required)</em><em id="UserTextPasswordUpdate"></em>'));
                //
                $image = $this->Html->tag('div','', array('class' => 'captcha', 'id' => 'captcha'));
                $changeCaptcha = $this->Html->link(__('Get New word', true), '#', array('id' => 'change-captcha'));
                echo $this->Html->div('captcha-wrap', sprintf('<div id="captchaError"></div> %s %s', $image, $changeCaptcha), array('id' => 'captcha-wrap'));
                echo $this->Form->input('captcha', array('label' => __('Type word about:', true), 'id' =>'textCaptcha'));


                echo $this->Html->tag('div','<span class="term_of_use"><input type="checkbox" id="TermOfUse" value="0">'.__('I have read and agree to the ', true).$this->Html->link(__('fascinating terms of service.', true), array('controller' => 'helps', 'action' => 'term')).'</span>', array('class' => 'wrap_term_of_use'));
                echo $form->button('Signup', array('type' => 'button','id' => 'buttonSignup', 'class' => 'button white'));
	?>
	</fieldset>
<?php

	echo $form->end();
?>
</div>
<?php 
	//check name;
	$this->Js->get('#UserName');
	$this->Js->event('blur', 'validate("#UserName", "", 6, false);');
	
	//check username;
	$this->Js->get('#UserUsername');
	$usernameUrl = $this->base.'/users/checkUsername';
	$this->Js->event('blur', 'validate("#UserUsername", "'.$usernameUrl.'", 5, false);');
	
	//check email
	$this->Js->get("#UserEmail");
	$emailUrl = $this->base.'/users/checkEmail';
	$this->Js->event('blur', 'validate("#UserEmail", "'.$emailUrl.'", 0, true);');
	
	//check password;
	$this->Js->get('#UserTextPassword');
	$this->Js->event('blur', 'validate("#UserTextPassword", " ", 6, false);');
	
	//button Signup
         $urlCheckCaptcha = Router::url(array('controller'=>'users', 'action' => 'checkCaptcha'));
         $verifyAll = __('<em class=\"message_error\">Please check all fields are required that have errors.</em>', true);
         $term = __('<em class=\"message_error\">If you don’t agree you can’t use Bayonpage.com.</em>', true);
	$this->Js->get('#buttonSignup');
	$this->Js->event('click', 'submitSignup("#UserSignup","'. $verifyAll.'","'.$term .'", "'.$urlCheckCaptcha.'");');

        $this->Js->get('#change-captcha');
        $this->Js->event('click',
                $this->Js->request(
                        array('controller' => 'users', 'action' => 'changeCaptcha'),
                        array('before' => '$("#captcha").html("loading...")', 'update' => '#captcha')
                   )
                );
       
?>
<script type="text/javascript">
   
    $('document').ready(function(){
        $(':checkbox').map(function(){
            return this.checked = false;

        });
       $('#TermOfUse').click( function(event){

        if(this.checked == true){
            $('#TermOfUse').attr('value', 1);
        }else{
            $('#TermOfUse').attr('value', 0);
        }
        return true;
     });
     
     /*
    $('#textCaptcha').bind('blur', function(){
        
    });
    */
    //ajax request
    $.ajax({beforeSend:function (XMLHttpRequest) {$("#captcha").html("loading...")}, dataType:"html", success:function (data, textStatus) {$("#captcha").html(data);}, url:"<?php echo Router::url(array('controller'=>'users', 'action' => 'changeCaptcha'))?>"});
     return false;

   });

</script>